﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace WinApp.Until
{
    public class RoundOK
    {       

        #region Public extern methods

        [DllImport("gdi32.dll")]
        public static extern int CreateRoundRectRgn(int x1, int y1, int x2, int y2, int x3, int y3);

        [DllImport("user32.dll")]
        public static extern int SetWindowRgn(IntPtr hwnd, int hRgn, Boolean bRedraw);

        [DllImport("gdi32.dll", EntryPoint = "DeleteObject", CharSet = CharSet.Ansi)]
        public static extern int DeleteObject(int hObject);

        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        #endregion
    }
    public class RoundHelper
    {

        public static void SetFormRoundRectRgn(Form form, int rgnRadius)
        {
            int hRgn = 0;
            hRgn = RoundOK.CreateRoundRectRgn(0, 0, form.Width, form.Height, rgnRadius, rgnRadius);
            RoundOK.SetWindowRgn(form.Handle, hRgn, true);
            RoundOK.DeleteObject(hRgn);
        }
        public static void SetPanelRoundRectRgn(Panel panel, int rgnRadius)
        {
            int hRgn = 0;
            hRgn = RoundOK.CreateRoundRectRgn(0, 0, panel.Width, panel.Height, rgnRadius, rgnRadius);
            RoundOK.SetWindowRgn(panel.Handle, hRgn, true);
            RoundOK.DeleteObject(hRgn);
        }
        public static void SetLabelRoundRectRgn(Label label, int rgnRadius)
        {
            int hRgn = 0;
            hRgn = RoundOK.CreateRoundRectRgn(0, 0, label.Width, label.Height, rgnRadius, rgnRadius);
            RoundOK.SetWindowRgn(label.Handle, hRgn, true);
            RoundOK.DeleteObject(hRgn);
        }
        public static void SetButtonRoundRectRgn(Button Button1, int rgnRadius)
        {
            int hRgn = 0;
            hRgn = RoundOK.CreateRoundRectRgn(0, 0, Button1.Width, Button1.Height, rgnRadius, rgnRadius);
            RoundOK.SetWindowRgn(Button1.Handle, hRgn, true);
            RoundOK.DeleteObject(hRgn);
        }
    }
}
